/*
 * ULSF Sagittarius IDA 
 * Copyright (C) 2012, John Pritchard, all rights reserved.
 * 
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */
package sagittarius.airfoil;

/**
 * Multiple geometries
 * 
 * @see Airfoil
 * @see NACA
 */
public class ModelVertices
    extends MathAbstract
    implements Cloneable,
               Iterable<AirfoilVertices>
{


    private AirfoilVertices[] list = new AirfoilVertices[Geometry.Count];


    public ModelVertices(){
        super();
    }


    public boolean hasModelVertices(Geometry geometry){
        return (null != this.list[geometry.ordinal()]);
    }
    public boolean isInitializedModelVertices(Geometry geometry){
        AirfoilVertices foil = this.getModelVertices(geometry);
        if (null != foil)
            return foil.isInitialized();
        else
            return false;
    }
    public boolean isTransformedModelVertices(Geometry geometry){
        AirfoilVertices foil = this.getModelVertices(geometry);
        if (null != foil)
            return foil.isTransformed();
        else
            return false;
    }
    public int countModelVertices(Geometry geometry){
        AirfoilVertices list = this.list[geometry.ordinal()];
        if (null == list)
            return 0;
        else
            return list.np;
    }
    public AirfoilVertices getModelVertices(Geometry geometry){
        return this.list[geometry.ordinal()];
    }
    public AirfoilVertices copyModelVertices(Geometry geometry){
        AirfoilVertices list = this.list[geometry.ordinal()];
        if (null != list){
            list = list.clone();
        }
        return list;
    }
    public AirfoilVertices setModelVertices(AirfoilVertices vary){

        return (this.list[vary.geometry.ordinal()] = vary);
    }
    public AirfoilVertices copyModelVertices(AirfoilVertices vary){
        if (null != vary)
            return (this.list[vary.geometry.ordinal()] = vary.clone());
        else
            return (this.list[vary.geometry.ordinal()] = null);
    }
    public AirfoilVertices generate(Geometry from, Geometry to){

        AirfoilVertices list = this.list[from.ordinal()];
        if (null != list)

            return this.setModelVertices(new AirfoilVertices(list,to));
        else
            throw new IllegalArgumentException(String.format("Missing vertex set from '%s'",from.name()));
    }
    public ModelVertices clone(){
        try {
            ModelVertices clone = (ModelVertices)super.clone();
            clone.list = clone.list.clone();
            return clone;
        }
        catch (CloneNotSupportedException exc){
            throw new InternalError();
        }
    }
    public java.util.Iterator<AirfoilVertices> iterator(){
        return new AirfoilVertices.Iterator(this.list);
    }
    public void dispose(){

        for (AirfoilVertices vertices: this){

            vertices.dispose();
        }
    }
}
